//
//  CueSelectionViewController.swift
//  SwitfTest
//
//  Created by runone02 on 2019/1/15.
//  Copyright © 2019年 liqiyun. All rights reserved.
//

import UIKit

class CueSelectionViewController: BaseViewController,UITableViewDelegate,UITableViewDataSource,JWAutoScrollViewDelegate {
  
    var CueTableView : UITableView!
    /// 轮播图
    let autoScrollView:JWAutoScrollView = JWAutoScrollView()
    private var dataArr : NSMutableArray!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.dataArr = ["加载成功","加载失败","展示信息","加载中","多个选择","多选","单选","时间选择","WebView展示"]
        addCueTableView()
    }

    
    
    func addCueTableView() {

        let btn1 = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
        btn1.setTitle("选择", for: .normal)
        btn1.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        btn1.setTitleColor(UIColor.black, for: .normal)
        btn1 .addTarget(self, action: #selector(btnClick), for:.touchUpInside)
        let item2 = UIBarButtonItem(customView: btn1)
        self.navigationItem.rightBarButtonItem = item2

        CueTableView = UITableView()
        CueTableView.backgroundColor = UIColor.white
        CueTableView.dataSource = self
        CueTableView.delegate = self
        CueTableView.showsVerticalScrollIndicator = false
        CueTableView.separatorColor = RGBAlpa(232,232,232,1)
        
        CueTableView.register(CueTableViewCell.self, forCellReuseIdentifier: "HomeCell")
        CueTableView.rowHeight = 50
        view.addSubview(CueTableView)
        CueTableView.mas_makeConstraints { (make) in
            make?.top.mas_equalTo()(view)?.offset()(250)
            make?.left.mas_equalTo()(view)
            make?.right.mas_equalTo()(view)
            make?.bottom.mas_equalTo()(view)
        }
        //轮播图
        self.automaticallyAdjustsScrollViewInsets = false
        autoScrollView.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: 250)
        autoScrollView.delegate = self
        view.addSubview(autoScrollView)
    }
    
    /// 选择
    @objc func btnClick(sender:UIButton){
        let alertController:JWAlertController = JWAlertController(preferredStyle: JWAlertControllerStyle.popover, sourceView: sender)
        
        alertController.addAction(actionTitle: "联系客服", actionStyle: .default, handler: { (action) in
            print(action.title as Any)
        })
        alertController.addAction(actionTitle: "联系卖家", actionStyle: .default, handler: { (action) in
            print(action.title as Any)
        })
        alertController.addAction(actionTitle: "选择", actionStyle: .default, handler: { (action) in
            print(action.title as Any)
        })
        alertController.addAction(actionTitle: "联系", actionStyle: .default, handler: { (action) in
            print(action.title as Any)
        })
        alertController.addAction(actionTitle: "卖家", actionStyle: .default, handler: { (action) in
            print(action.title as Any)
        })
        self.present(alertController, animated: true, completion: {
            
        })
    }
    
    
    //每一次自动滚动停止
    func autoScrollView(autoScrollView: JWAutoScrollView, didEndAnimationAt itemIndex: Int) {
        
    }
    
    //返回自动滚动的个数
    func autoScrollViewNumberOfPage() -> Int {
        return 4
    }
    
    //本方法将 每一个item返回，使用者可以通过框架加载图片  也可以直接设置本地图片
    func autoScrollView(autoScrollView: JWAutoScrollView, index: Int, imageButton: JWAutoScrollViewButton) {
        imageButton.setImage(UIImage(named:String(format:"%zd",index)), for: UIControl.State.normal)
        
    }
    
    //点击选中
    func autoScrollView(autoScrollView: JWAutoScrollView, didSelectedItemAt itemIndex: Int) {
        print(itemIndex)
    }
    


    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier:  "HomeCell", for: indexPath) as! CueTableViewCell
        cell.titelLabel.text = self.dataArr[indexPath.row] as? String
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
       
        if(indexPath.row == 0){  //加载成功
            JavenHUD.showMessage(message: "加载成功", type: JWProgressHUDType.success, complectionClosure: {
                //成功
            })
        } else if(indexPath.row == 1){  //加载失败
            JavenHUD.showMessage(message: "加载失败", type: JWProgressHUDType.error, complectionClosure: {
                //成功
            })
        }else if(indexPath.row == 2){   ///文字展示
            JavenHUD.showMessage(message: "展示纯文字的信息，不想使用带图标的失败或成功提示，可以直接用它来代替", type: JWProgressHUDType.message, complectionClosure: {
                //成功
            })
        }
        else if(indexPath.row == 3){  //加载中
            JavenHUD.showMessage(message: "", type: JWProgressHUDType.loading, complectionClosure: {
                //加载中
            })
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+2.5, execute: {
                if arc4random_uniform(100)%2==0{
                    JavenHUD.showMessage(message: "", type: JWProgressHUDType.dismiss, complectionClosure: {
                        //消失
                    })
                }else{
                    JavenHUD.showMessage(message: "加载成功", type: JWProgressHUDType.success, complectionClosure: {
                        //成功
                    })
                }
            })
        }else if(indexPath.row == 4){   //单选
            let alertController:JWAlertController = JWAlertController(preferredStyle: JWAlertControllerStyle.actionSheet)
            alertController.addAction(actionTitle: "相机", actionStyle: .default, handler: { (action) in
                 print("相机点击")
            })
            alertController.addAction(actionTitle: "相册", actionStyle: .default, handler: { (action) in
                 print("相册点击")
            })
            alertController.addAction(actionTitle: "查看大图", actionStyle: .default, handler: { (action) in
                print("查看大图点击")
            })
            alertController.addAction(actionTitle: "取消", actionStyle: .default, handler: { (action) in
                 print("取消点击")
            })
            //弹出
            self.present(alertController, animated: true, completion: {
                
            })
        }else if(indexPath.row == 5){   //多选
            let alertController:JWAlertController = JWAlertController(title: "温馨提示", message: "确认要删除吗？", preferredStyle: JWAlertControllerStyle.alert)
            alertController.addAction(actionTitle: "直接删除", actionStyle: .default, handler: { (action) in
                
            })
            alertController.addAction(actionTitle: "查看详情", actionStyle: .default, handler: { (action) in
                
            })
            alertController.addAction(actionTitle: "取消", actionStyle: .default, handler: { (action) in
                
            })
            self.present(alertController, animated: true, completion: {
                
            })
        }else if (indexPath.row == 6){///提示选择
            let alertController:JWAlertController = JWAlertController(title: "好评提醒", message: "亲，给个好评吧，我们非常需要您的鼓励哦！", preferredStyle: JWAlertControllerStyle.alert)
            
            alertController.addAction(actionTitle: "立即好评", actionStyle: .default, handler: { (action) in
                
            })
            alertController.addAction(actionTitle: "残忍拒绝", actionStyle: .default, handler: { (action) in
                
            })
            
            self.present(alertController, animated: true, completion: {
                
            })
        }else if (indexPath.row == 7){//时间选择
            let newVC = JWDatePickerViewTestViewController()
            navigationController?.pushViewController(newVC, animated: true)
            
        }else if (indexPath.row == 8){  ///webView展示
            let webTestVc:JWWebViewController = JWWebViewController()
            webTestVc.urlString = "https://www.baidu.com"
            self.navigationController?.pushViewController(webTestVc, animated: true)
        }
        else{
            
        }
        
    }
    
    


}
